#!/bin/bash
source ~/catkin_ws/devel/setup.bash
source /opt/ros/noetic/setup.bash
source /home/orangepi/cartographer_ws/install_isolated/setup.bash
source /home/orangepi/anorosdt_ws/devel/setup.bash

# 查找目标进程ID
target_cmd="gnome-terminal -- bash -c "source /opt/ros/noetic/setup.bash; source /home/orangepi/cartographer_ws/install_isolated/setup.bash; source /home/orangepi/anorosdt_ws/devel/setup.bash; roslaunch anorosdt anoros_dt.launch; exec bash""
process_id=$(pgrep -f "$target_cmd")

if [ -n "$process_id" ]; then
    
    # 终止roslaunch进程（优雅退出）
    kill -SIGINT "$process_id"
    sleep 2
    
    # 若进程仍在，强制终止
    if ps -p "$process_id" > /dev/null; then
        kill -9 "$process_id"
    fi
    
else
    echo "目标进程未运行。"
fi

roslaunch anorosdt anoros_dt.launch

exit 0
